<?php
/**
 * Created by JetBrains PhpStorm.
 * User: T420
 * Date: 10/24/12
 * Time: 8:37 AM
 * To change this template use File | Settings | File Templates.
 */
class Controllers_Index extends Libs_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->model= new Models_Index();
    }
    public function index()
    {

        $order=$this->model->getneworder();
        $user=$this->model->getuser();
        $this->view->numberorder=count($order);
        $this->view->numberuser=count($user);
        $this->view->render('index/index');


    }
    public function salereport($param=null)
    {
       $this->view->render('index/salereport');
        if($param[0]!='')
        {

        }
    }
    public function login()
    {


        $this->view->render('index/login',false);

        if(isset($_POST['login']))
        {

            $login=new Models_Login();
            $emname=$_POST['emname'];
            $pass=$_POST['password'];

            $process=$login->getlogin($emname,$pass);
            if(count($process)>0)
            {
                foreach($process as $key=>$value)
                {
                    $_SESSION['userid']=$value->emid;
                    $_SESSION['username']=$value->emname;
                    $_SESSION['grade']=$value->grade;
                    echo '<script type="text/javascript">location="/mymvc/administrator"</script>';
                }

            }
            else
                echo '<script type="text/javascript">alert("Sai thông tin đăng nhập")</script>';
        }
    }
    public function logout()
    {

        $_SESSION['username']="";
        $_SESSION['grade']="";
        echo '<script type="text/javascript">location="/mymvc/administrator"</script>';

    }

}
